/*
 * @Author: Fu Zhuohang
 * @Date: 2021-12-23 10:07:16
 * @LastEditors: Fu Zhuohang
 * @LastEditTime: 2022-02-25 16:19:32
 * @FilePath: \yunshu6.0-2\entries\mobile\src\views\apps\report-service.ts
 * @Description: 
 */

import ReportOptions from '@h3/report/dist/options';
import reportOrg from "./report-org.vue";
import ReportAddress from "./report-address.vue";
import ReportDropdown from "./report-dropdown.vue";
let inited = false;
import { schema } from '@cloudpivot/form';

import env from '@/config/env';
import {DataItemType} from "@cloudpivot/form/src/schema";

export function init() {

    if (inited) {
        return;
    }

    inited = true;

    ReportOptions.baseUrl = env.portalHost;
    ReportOptions.charts = { list: { dimension: 50 } };
    
    ReportOptions.download.list = true;
    ReportOptions.download.pivotTable = true;
    
    ReportOptions.requestHeader = () => {
        const token = localStorage.getItem('token');
        if(!token){
            return null;
        }

        return {
            Authorization : 'Bearer ' + token
        }
    }
    ReportOptions.integrateComponents = (field: any,formula:string,format:string): any | null => {
      let components: any = null;
      switch (field.dataType) { 
        case schema.DataItemType.Address:
            components = ReportAddress;
            break;
      }
      switch (field.dataType) {
        case schema.DataItemType.StaffSingle:
        case schema.DataItemType.StaffMulti:
        case schema.DataItemType.DeptSingle:
        case schema.DataItemType.DeptMulti:
        case schema.DataItemType.StaffDeptMix:
          components = reportOrg;
          break;
        case DataItemType.Dropdown:
        case DataItemType.Checkbox:
        case DataItemType.Radio:
        case DataItemType.DropdownMulti:
            console.log(format,"0")
            if(format === '2'){
                components = ReportDropdown;
            }
            break;
      }
      return components;
    };

}

init();